package net.trombonium.steroid;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.*;

import org.apache.http.client.methods.*;
import org.apache.http.client.*;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
//import org.apache.http.protocol.*;
import org.apache.http.*;

import android.util.Log;


public class PostMe {
	private static final String TAG = "PostMe";
	
	public static void PostOverHttp(String filename, String url) throws Exception {
	
		HttpClient httpclient = new DefaultHttpClient(); 
		
		File file = new File(filename);  //This is our Result file on Phone.
		HttpPost httppost = new HttpPost(url);
		
		InputStreamEntity reqEntity = new InputStreamEntity (new FileInputStream(file), -1); 
		
		reqEntity.setContentType("application/x-www-form-urlencoded");
	    
	    Header[] headers = new BasicHeader[2];
	    headers[0] = new BasicHeader("Accept","application/xml");  //This is a standard header 1, I guess!
	    headers[1] = new BasicHeader("Content-type", "application/x-www-form-urlencoded"); //This is a standard header 1
	    httppost.addHeader(headers[0]);
	    httppost.addHeader(headers[1]);
	 
	    httppost.setEntity(reqEntity);
	   
	    HttpResponse response = httpclient.execute(httppost);   // It executes "httppost" and return out come 
	    
	    Log.i(TAG, response.toString()); // If we want to add anything to our Log file from execute(httppost)
	    InputStream rstream = response.getEntity().getContent();
	    int i;
	    String r = "";
	    while((i=rstream.read())!=-1){
	    	r += (char)i;
	   	}
	    Log.i(TAG, r);
	}
}
